﻿using PersistentObject.Common.Exceptions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace PersistentObject.Common.Criteria
{
    /// <summary>
    /// Represent an OR clause
    /// </summary>
    public class OrCriteria : BaseCriteria
    {
        /// <summary>
        /// Indicate the list of criteria in OR clause
        /// </summary>
        public List<BaseCriteria> CriteriaList { get; private set; }

        public OrCriteria()
        {

        }

        public OrCriteria(BaseCriteria first)
        {
            CriteriaList = new List<BaseCriteria>();

            if (first!= null)
            {
                CriteriaList.Add(first);
            }
        }

        /// <summary>
        /// Initialize an OR criteria which requires TWO criteria(s)
        /// </summary>
        /// <param name="first">Indicate the FIRST criteria in OR clause</param>
        /// <param name="second">Indicate the SECOND criteria in OR clause</param>
        public OrCriteria(BaseCriteria first, BaseCriteria second)
        {
            CriteriaList = new List<BaseCriteria>();

            if (first != null)
            {
                CriteriaList.Add(first);
            }
            if (second != null)
            {
                CriteriaList.Add(second);
            }
        }

        /// <summary>
        /// The constructor of OR criteria which requires THREE criteria(s)
        /// </summary>
        /// <param name="first">Indicate the FIRST criteria in OR clause</param>
        /// <param name="second">Indicate the SECOND criteria in OR clause</param>
        /// <param name="third">Indicate the THIRD criteria in OR clause</param>
        public OrCriteria(BaseCriteria first, BaseCriteria second, BaseCriteria third)
            :this(first, second)
        {
            if (third != null)
            {
                CriteriaList.Add(third);
            }
        }

        /// <summary>
        /// The constructor of OR criteria which requires FOUR criteria(s)
        /// </summary>
        /// <param name="first">Indicate the FIRST criteria in OR clause</param>
        /// <param name="second">Indicate the SECOND criteria in OR clause</param>
        /// <param name="third">Indicate the THIRD criteria in OR clause</param>
        /// <param name="fourth">Indicate the FOURTH criteria in OR clause</param>
        public OrCriteria(BaseCriteria first, BaseCriteria second, BaseCriteria third, BaseCriteria fourth)
            : this(first, second, third)
        {
            if (fourth != null)
            {
                CriteriaList.Add(fourth);
            }
        }

        /// <summary>
        /// The constructor of OR criteria which requires FIVE criteria(s)
        /// </summary>
        /// <param name="first">Indicate the FIRST criteria in OR clause</param>
        /// <param name="second">Indicate the SECOND criteria in OR clause</param>
        /// <param name="third">Indicate the THIRD criteria in OR clause</param>
        /// <param name="fourth">Indicate the FOURTH criteria in OR clause</param>
        /// <param name="fifth">Indicate the FIFTH criteria in OR clause</param>
        public OrCriteria(BaseCriteria first, BaseCriteria second, BaseCriteria third, BaseCriteria fourth, BaseCriteria fifth)
            : this(first, second, third, fourth)
        {
            if (fifth != null)
            {
                CriteriaList.Add(fifth);
            }
        }

        /// <summary>
        /// The constructor of OR criteria which requires a collection of criteria(s)
        /// </summary>
        /// <param name="collection">Indicate the collection of criteria in OR clause</param>
        public OrCriteria(IEnumerable<BaseCriteria> collection)
        {
            CriteriaList = new List<BaseCriteria>();

            CriteriaList.AddRange(collection);
        }

    
    }
}
